import { Ref, ref } from 'vue'
import { AxiosResponse } from 'axios'
import homeApi from '@/api/homeApi'
import ObjUtil from '@/utils/objUtil'
const { deepClone } = ObjUtil
export const checkTypecolumns = ref([
  { text: '不限', value: '' },
  { text: '超声', value: 'UIS' },
  { text: '放射', value: 'RIS' },
  { text: '内镜', value: 'EIS' },
  { text: '检验', value: 'LIS' },
  { text: '病理', value: 'PIS' }
])
export const deptTypecolumns = ref([
  { text: '不限', value: '' },
  { text: '骨科', value: '骨科' },
  { text: '急诊', value: '急诊' },
  { text: '妇科', value: '妇科' },
  { text: '产科', value: '产科' },
  { text: '儿科', value: '儿科' },
  { text: '五官科', value: '五官科' },
  { text: '外科', value: '外科' },
  { text: '内科', value: '内科' },
  { text: '眼科', value: '眼科' },
  { text: 'ICU', value: 'ICU' },
  { text: '放射科', value: '放射科' },
  { text: '病理科', value: '病理科' },
  { text: '内镜科', value: '内镜科' },
  { text: '系统科', value: '系统科' }
])
export interface Exam {
  age: string
  describes: string
  diagnosis: string
  fromDeptName: string
  fromDocName: string
  id: string
  inPatientNo: string
  isFinished: string
  machineName: string
  machineType: string
  moduleName: string
  name: string
  oldDocID: string
  outPatientNo: string
  reportDate: string
  reportTime: string
  sex: string
  sickBedNo: string
  visceras: string
}
export interface Form {
  StartExamDate: string
  EndExamDate: string
  Name: string
  Sex: string
  StartAge: string
  EndAge: string
  OutPatientNo: string
  InPatientNo: string
  OldDocID: string
  SickBedNo: string
  ModuleName: string
  FromDeptName: string
  FromDocName: string
}

interface FindExamList {
  rows: Exam[]
  totalCount: number
}

export interface Dicom {
  modality: string
  numImages: string
  patientId: string
  patientName: string
  seriesList: any
  studyDate: string
  studyDescription: string
  studyID: string
}

export type PartialForm = Partial<Form>

class UseSearchForm {
  static useSearchForm = new UseSearchForm()
  static page: number = 1
  static size: number = 10
  static form: PartialForm
  static totalCount = ref(0)
  examList: Ref<Exam[] | null> = ref(null)
  isFinished: Ref<boolean> = ref(false)
  isLoading: Ref<boolean> = ref(false)

  async findExamList(data: PartialForm) {
    UseSearchForm.reset()
    const { page, size } = UseSearchForm
    UseSearchForm.form = deepClone(data)
    const res: AxiosResponse<FindExamList> = await homeApi.findExamList(
      page,
      size,
      data
    )
    console.log(res)
    if (res.data.rows.length) {
      UseSearchForm.useSearchForm.isLoading.value = false
    }
    UseSearchForm.totalCount.value = res.data.totalCount
    UseSearchForm.useSearchForm.examList.value = res.data.rows
  }
  static reset() {
    UseSearchForm.useSearchForm.examList.value = []
    UseSearchForm.page = 1
    UseSearchForm.size = 10
    UseSearchForm.useSearchForm.isFinished.value = false
    UseSearchForm.useSearchForm.isLoading.value = false
  }
}

export default UseSearchForm
